package project.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import project.pojo.Teacher;
import project.service.TeacherService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/updateTeacherInfoServlet")
public class UpdateTeacherInfoServlet extends HttpServlet {
    private TeacherService teacherService = new TeacherService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader reader = request.getReader();
        String s = reader.readLine();

        Teacher teacher = JSON.parseObject(s, Teacher.class);
        System.out.println(teacher);
        boolean flag = teacherService.updateTeacherInfo(teacher);

        if(flag){
            response.getWriter().write("success");
        }else{
            response.getWriter().write("unsuccess");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
